<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/10/5
  Time: 18:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title>$Title$</title>
    <style>
        table tr:nth-child(odd) {
            background: darkgray;
        }

        a {
            text-decoration: none;
        }
    </style>
    <script src="jq/jquery.js"></script>
</head>
<body>
<h1 align="center">新能源汽车动力电池信息</h1>
<table border="1px" align="center">
    <tr style="background: lightgray" align="center">
        <th>编号</th>
        <th>车型</th>
        <th>所属城市</th>
        <th>使用单位</th>
        <th>压差报警值</th>
        <th>报警时间</th>
        <th>操作</th>
    </tr>
    <c:forEach var="pb" items="${sessionScope.list}">
        <tr align="center">
            <td><a href="PowerBatteryServlet?id=${pb.id}">${pb.id}</a></td>
            <td>${pb.carName}</td>
            <td>${pb.cityName}</td>
            <td>${pb.userName}</td>
            <td>${pb.pressureValue}</td>
            <td>${pb.time}</td>
            <td><a href="javascript:void(0)" onclick="remove('${pb.id}')">删除</a></td>
        </tr>
    </c:forEach>
</table>
<script>
    function remove(id) {
        if (confirm("确认删除吗？")) {
            $.getJSON(
                "DeleteServlet",
                {id: id},
                function (data) {
                    if (data) {
                        alert("删除成功");
                        location.href = 'ListServlet'
                    } else {
                        alert("删除失败")
                    }
                }
            )
        }
    }
</script>
</body>
</html>
